unit EditPlayerNotes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, umainutils, StdCtrls, Oracle, uSQLs, gnugettext, uutils;

type
  TuFrmEditPlayerNotes = class(TForm)
    pnl_Buttons: TPanel;
    btn_Save: TSpeedButton;
    btn_Close: TSpeedButton;
    OracleQuery1: TOracleQuery;
    Label1: TLabel;
    memo: TMemo;
    procedure btn_SaveClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btn_CloseClick(Sender: TObject);
  private
    { Private declarations }
    m_IsClone, m_IsEdit: boolean;
    m_recordID: string;
  public
    procedure ShowForm(IsEdit, IsClone: boolean; recordID: string);
    { Public declarations }
  end;

var
  uFrmEditPlayerNotes: TuFrmEditPlayerNotes;

implementation

uses UfrmMain;
{$R *.dfm}
{ TuFrmEditPlayerNotes }

procedure TuFrmEditPlayerNotes.btn_CloseClick(Sender: TObject);
begin
  close();
end;

procedure TuFrmEditPlayerNotes.btn_SaveClick(Sender: TObject);
begin
  if m_IsClone or (not m_IsEdit) then
  begin
    InsertDataIntoDB('PLAYER_NOTES', 'NOTE,PLAYER_ID,DATETIME', '''' + memo.Text + ''', ''' + FrmMain.FraPlayersMain.stg_Players.Cells[0, FrmMain.FraPlayersMain.stg_Players.Row]
        + ''', ' + 'to_date(''' + GetFormatedStringDateNOW(FrmMain.OracleSession1) + ''', ''dd.mm.yyyy hh24:mi:ss'')');
  end
  else
  begin
    UpdateDataToDB('PLAYER_NOTES', 'NOTE=''' + memo.Text + ''',PLAYER_ID=''' + FrmMain.FraPlayersMain.stg_Players.Cells[0, FrmMain.FraPlayersMain.stg_Players.Row]
        + ''',DATETIME=' + 'to_date(''' + GetFormatedStringDateNOW(FrmMain.OracleSession1) + ''', ''dd.mm.yyyy hh24:mi:ss'')', 'ID=' + m_recordID);
  end;
  FrmMain.GetGridData(FrmMain.FraPlayersMain.stg_PlayerNotes, SQL_Player_Notes + FrmMain.FraPlayersMain.stg_Players.Cells[0, FrmMain.FraPlayersMain.stg_Players.Row], false);
  FrmMain.FraPlayersMain.stg_PlayerNotesSelectCell(self, 0, FrmMain.FraPlayersMain.stg_PlayerNotes.Row, canselect);
  close();
end;

procedure TuFrmEditPlayerNotes.FormKeyPress(Sender: TObject; var Key: Char);
begin
  // The Escape key is #27.
  if Key = #27 then
    close
  else if Key = #13 then
    btn_Save.Click;
end;

procedure TuFrmEditPlayerNotes.ShowForm(IsEdit, IsClone: boolean; recordID: string);
var
  Query: string;
begin
  m_IsClone := IsClone;
  m_IsEdit := IsEdit;
  m_recordID := recordID;
  OracleQuery1.Session := FrmMain.OracleSession1;
  memo.Text := '';
  if IsEdit then
  begin
    Query := 'select id, note from PLAYER_NOTES where id=' + recordID;
    OracleQuery1.SQL.Clear;
    OracleQuery1.SQL.Text := (Query);
    OracleQuery1.Execute;
    memo.Text := OracleQuery1.Field('NOTE');
  end;
  ShowModal();
end;

end.
